package com.sth.shishan;

import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.util.List;

/**
 * @Author: sitianhong
 * @Description: 博客网站的案例
 * @Since: create in 2021/6/13 0013 17:06
 */
public class RedisDemo3 {
    Jedis jedis = new Jedis("127.0.0.1", 6378);

    @Test // 实现 社交网站点击追踪机制1
    public void demo1() {
        publishBolg(1, "博客", "redis", "sitianhong", "博客的小demo");
        List<String> blog = getBlog(1);
        System.out.println("访问次数 " + blog.toString());
    }

    public void publishBolg(long id, String title, String content, String author, String item) {
        jedis.mset("article:" + id + ":title", title, "article:" + id + ":content", content,
                "article:" + id + ":author", author, "article:" + id + ":item", item);
    }

    public List<String> getBlog(long id) {
        List<String> mget = jedis.mget("article:" + id + ":title", "article:" + id + ":content",
                "article:" + id + ":author", "article:" + id + ":item");
        return mget;
    }
}
